Skip to content

fork↔replicas convergence: pinned fork_base checkpoints (#2960 ②) - #3014

Merged
ranxianglei merged 1 commit into
2026-10-13_ccr-retirementfrom
2026-10-13_fork-replica-convergence
Oct 13, 2026
Merged

ranxianglei merged 1 commit into
2026-10-13_ccr-retirementfrom
2026-10-13_fork-replica-convergence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Step ② of the #2960 roadmap (see the plan comment): every plugin fork now cuts a pinned fork_base checkpoint into the unified index, at the same flush that persists the fork receipt.

  • SessionStore.maybeCutForkBase runs after writeNow/flushSync. Gate: unified sidecar live and (publicForkReceipt present or publicSnapshotRetained === true) and pluginSnapshot non-empty — i.e. exactly the sessions whose fork substrate is worth pinning. The checkpoint blob is the full buildRecord envelope (kind fork_base, label fork-base <id>, pinned: true).
  • Memoized per session (in-memory Set + a listCheckpoints probe) so steady-state writes don't re-query; a failed cut logs one warn and never blocks the write path.
  • deleteSession (from Identity pipeline R2 v1: namespace + origin columns + #2847 proof suite (#2960) #2963/Fix: #2815 review follow-ups — persisted-chain tiebreaker, schema v2, safe word-bag digest #2988 review fixes) already sweeps only unpinned checkpoints — so fork substrate now survives parent deletion, and a deleted parent can be resurrected wholesale via the replicas API (restoreReplica) with an identical ordered snapshot.

Why this shape

  • The unified index already tables plugin snapshots (planIngest interns pluginSnapshot ∪ lastMessages; loadLegacyView rebuilds it from tailJson.pluginSnapshotSeqs) — so full mode already serves snapshots from the DB. What was missing is a deletion-proof pin, which is the exact substrate Phase 3 (envelope jsonWriter: off) needs before the legacy snapshot blob can be dropped.
  • Parent and child each get their own fork_base: the child's receipt and the parent's retained snapshot are symmetric substrates (independent lineage proven by the test).

Tests

  • tests/fork-replica-convergence.test.ts (new):
    • full: seed → snapshot → fork (v1 protocol) → both sides have exactly one pinned fork_base; deleteSession(parent) leaves the pinned row and the child fully functional; restoreReplica resurrects the parent under a fresh id with orderedMessages deep-equal to the original; the child is unaffected.
    • legacy control: fork works, no index.db ever created (rollback contract unchanged).
  • Regression: plugin-fork/storage families — 89 pass / 1 skip / 0 fail (6 files), fork-adoption-wires + persist-tail + identity + review-fixes + export-jsonl + golden-render 30/30. tsc clean.

Stack

#2998 (R2.2) ← #3007 (⑤ raw tail) ← #3010 (③ CCR mirror) ← this PR. Each is independently reviewable; bases retarget to master as the stack merges.

prepared by an agent under the local git identity (ranxianglei), human merge required

… ②)

- SessionStore.maybeCutForkBase: on writeNow/flushSync, when the unified
  sidecar is live and the session carries publicForkReceipt or
  publicSnapshotRetained, cut a pinned fork_base checkpoint holding the
  full buildRecord blob (kind: fork_base, label: 'fork-base <id>').
- Memoized per session (Set + listCheckpoints probe) so steady-state
  writes don't re-query; failure logs one warn and never blocks the write.
- deleteSession already skips pinned checkpoints — fork substrate now
  survives parent deletion and restores via restoreReplica.
- tests/fork-replica-convergence.test.ts: full-mode e2e (both sides cut,
  pinned survives deleteSession, child independent, parent resurrects with
  identical orderedMessages) + legacy control (no index.db).
@ranxianglei
ranxianglei merged commit e0a42dc into 2026-10-13_ccr-retirement Oct 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant